package com.keyinong.caizhengting.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.keyinong.caizhengting.R;
import com.keyinong.caizhengting.tools.HttpTools;
import com.keyinong.caizhengting.entity.MessageEntity;

import java.util.ArrayList;

/**
 * @author：郑谦
 * @时间：2017-3-20 下午3:47:52
 * @类名：MessageAdapter.java
 * @功能: 消息适配器
 */

public class MessageAdapter extends BaseAdapter {
    Context context;
    ArrayList<MessageEntity> messageList;
    HttpTools httpTools = null;

    public MessageAdapter(Context context, ArrayList<MessageEntity> messageList) {
        super();
        this.context = context;
        this.messageList = messageList;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return messageList.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return messageList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        final ViewHandle handle;
        if (view == null) {
            handle = new ViewHandle();
            view = LayoutInflater.from(context).inflate(R.layout.item_message, null);
            handle.tv_date = (TextView) view.findViewById(R.id.tv_date);
            handle.tv_message = (TextView) view.findViewById(R.id.tv_message);
            view.setTag(handle);
        } else {
            handle = (ViewHandle) view.getTag();
        }
        handle.tv_date.setText(messageList.get(position).getDate());
        handle.tv_message.setText(messageList.get(position).getContent());

        return view;
    }

    class ViewHandle {
        /**
         * 时间
         */
        TextView tv_date;
        /**
         * 数量
         */
        TextView tv_message;
//		TextView tv_sname;
    }
}
